package display;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

/**
 *@author Lei
 */
public class LeisDeadlyDisplay implements Display{
	
	public LeisDeadlyDisplay(){
		
	}
	
	private void init(){
		
	}

	@Override
	public int displayNumbers() {
		int number = 1;
		try{
			Registry registry = LocateRegistry.getRegistry();
			String[] registryComponents = registry.list();
			for (int i = 0; i < registryComponents.length; i++){
				if(registryComponents[i].startsWith("display")) 
					number++;
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return number;
	}
	
	public static void main(String[] args){
		TextBasedDisplayLarge ts = new TextBasedDisplayLarge();
		DisplayView view=new DisplayView();
		view.setVisible(true);
		try{
			int num = ts.displayNumbers();
			RMIServerImpl rmi = new RMIServerImpl("display"+num,view.getLabel());
			rmi.begin();
			BonjourService bs = new BonjourService("display"+num);
			bs.registerService();
		} 
		catch(Exception e){
			e.printStackTrace();
		}
	}
	
	

}